package com.qbm.association.controller;

import com.qbm.association.bean.ResultBean;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.MalformedJwtException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@RestControllerAdvice
public class GlobalExceptionController {

    @ExceptionHandler(Exception.class)
    public Object handleException(Exception e, HttpServletRequest req){
        /**
         * 返回错误信息
         */
        System.err.println(e.getMessage());
        e.printStackTrace();
        return ResultBean.fail(e.getMessage());

    }


    @ExceptionHandler(ExpiredJwtException.class)
    public Object handleJWTException(Exception e,HttpServletRequest req){
        /**
         * 返回错误信息
         */
        System.err.println(e.getMessage());
        e.printStackTrace();
        return ResultBean.overDue("登录过期，请重新登录");
    }



    @ExceptionHandler(MalformedJwtException.class)
    public Object handleJWTException2(Exception e,HttpServletRequest req){
        /**
         * 返回错误信息
         */
        System.err.println(e.getMessage());
        e.printStackTrace();
        return ResultBean.overDue("登录过期，请重新登录");
    }
}
